package com.cyy.ultra_ptr_demo.avtivity;

import android.os.Bundle;
import android.support.v7.app.AppCompatActivity;
import android.view.View;
import android.widget.ImageView;

import com.cyy.ultra_ptr_demo.R;

import butterknife.ButterKnife;
import butterknife.InjectView;
import butterknife.OnClick;
import in.srain.cube.views.ptr.PtrClassicFrameLayout;
import in.srain.cube.views.ptr.PtrDefaultHandler;
import in.srain.cube.views.ptr.PtrFrameLayout;

public class StringActivity extends AppCompatActivity {

    @InjectView(R.id.ptr_img)
    ImageView ptrImg;
    @InjectView(R.id.ptr_String)
    PtrClassicFrameLayout ptrString;

    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        setContentView(R.layout.activity_string);
        ButterKnife.inject(this);


        //设置开机自启动
        ptrString.postDelayed(new Runnable() {
            @Override
            public void run() {
                ptrString.autoRefresh();
            }
        },500);
        //设置下拉启动
        ptrString.setPtrHandler(new PtrDefaultHandler() {
            @Override
            public void onRefreshBegin(PtrFrameLayout frame) {
                ptrString.postDelayed(new Runnable() {
                    @Override
                    public void run() {
                        ptrString.refreshComplete();
                    }
                },2000);
            }
        });

    }




    @OnClick({R.id.ptr_img, R.id.ptr_String})
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.ptr_img:
                ptrString.autoRefresh();//点击自动刷新
                break;
            case R.id.ptr_String:
                break;
        }
    }
}
